﻿#ifndef GLOABDATA_H
#define GLOABDATA_H

#if defined(_MSC_VER) && (_MSC_VER >= 1600)
# pragma execution_character_set("utf-8")
#endif


#include "mylog.h"
#include "Console/tables.h"
#include "mygui.h"
//#include "Console/Server/SerialPort.h"
//#include "agreement.h"

class Config;
class SqlBase;
class HttpServer;
class TaskManager;
class SerialPort;

class GlobalData : public QObject
{
    Q_OBJECT

private:
    explicit GlobalData(QObject *parent = nullptr);

public:
    static GlobalData* GetInstance(void)
    {
        static GlobalData instance;
        return &instance;
    }

signals:
    void UpdateLog(QString log);
    void UserChange();

    void AudioMute(bool mute);
    void PlayUrl(QUrl url);
    void PlayerPause();
    void SetPlaySound(QString url);
    void Update();

    void seriPort();
    void Tcp();
    void TcpJX();
    void TcpZY();

    void updateantenna1(QString Kw,bool a,bool b);
    void updateantenna2(QString Kw,bool a,bool b);

    void DefeatedJX();
    void DefeatedZY();

public slots:
    void Init();
    void InitEquipment(); //从数据库取出数据放入list容器
    void UpdateEquipment();
    void InitIPData();
    void UpdateIPData();
    void critical(QString Kw);
    void criTicalSuccess(QString Kw);
    IPData* GetIPByName(QString name);

    int GetEquIndexByCode(QString code);
    Equipment* GetEquByCode(QString code);
    Simulation* GetSimByCode(QString code);
    State* GetStateByCode(QString code);

    void SaveSysLog(QString log, int type = 0);
    bool CheckUserRole(int role);

public:


    Config          *config;
    SqlBase         *sqlBase;
    User            user;
    Cos             *cos;

    HttpServer      *httpServer;
    TaskManager     *taskManager;

    bool            dataBaseOpen;
    bool            serialOpen;
    bool            Light_1=false;
    bool            Light_2=false;
    bool            Light_3=false;
    bool            Light_4=false;
    bool            Tower_50=true;
    bool            Tower_10=true;
    bool            Computer_50=true;
    bool            Computer_10=true;

    QMutex             mutex;
    QList<Equipment*>  equList;
    QList<Simulation*> simList;
    QList<State*>      stateList;
    QList<IPData*>     ipList;
   // QList<FrameFormat*> formatList;
};

#endif // GLOABDATA_H
